// pages/poetry/poetry.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zhi:'',
    sousuo:'null',
    url: 'https://tsn.baidu.com/text2audio?tex=黄一宸是好孩子&lan=zh&cuid=8c:16:45:92:0f:42&ctp=1&tok=24.5db0ce51d2a67d31366435311738a5ca.2592000.1595318495.282335-20518023',
    title:"",
    content:" ",
    author:" ",

    title1:"",
    content1:" ",
    author1:" ",

    title2:"",
    content2:" ",
    author2:" ",

    title3:"",
    content3:" ",
    author3:" ",

    title4:"",
    content4:" ",
    author4:" ",

    title5:"",
    content5:" ",
    author5:" ",

    title6:"",
    content6:" ",
    author6:" ",

    title7:"",
    content7:" ",
    author7:" ",

    title8:"",
    content8:" ",
    author8:" ",

    title9:"",
    content9:" ",
    author9:" ",
    flag1:0,
    flag2:0,
    array: ["1", "2", "3"],
  },
  switchNav1:function(e){
    var id = e.target.id;
    var page = this;
    if(this.data.flag1 == id){
      return false;
    }
    else{
      page.setData({flag1:id})
    }
  },
  switchNav2:function(e){
    var id = e.target.id;
    var page = this;
    if(this.data.flag2 == id){
      return false;
    }
    else{
      page.setData({flag2:id})
    }
  },
  switchItem1: function() {
    wx.navigateTo({
      url: '../poet/poet',
    })
    wx.setNavigationBarTitle({
      title: '热门诗人',
    })
  },
  switchItem2: function() {
    wx.navigateTo({
      url: '../book/book',
    })
    wx.setNavigationBarTitle({
      title: '热门典籍',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  input:function(e){
    this.setData({
      zhi: e.detail.value
    })
   
    console.log(this.data.zhi);
  },
  sousuo:function(options){
  
      wx.setStorageSync('zhi', this.data.zhi)
      console.log(this.data.zhi);   
      wx.navigateTo({
        url: '../lists/list'
      });
  },
  play:function(){
    var audio = wx.createInnerAudioContext()
    var url = "https://tsn.baidu.com/text2audio?tex=黄一宸是好孩子&lan=zh&cuid=8c:16:45:92:0f:42&ctp=1&tok=24.5db0ce51d2a67d31366435311738a5ca.2592000.1595318495.282335-20518023"
    audio.src = url
    audio.play()
    
  },
  onLoad: function (options) {
    var body;
    var that = this;
    
    wx.request({
      url: 'https://api.tianapi.com/txapi/poetries/index?key=2ed99a821e40641cc2d133e6de15cf52&word=李白&num=10', 
      success: function (res) {
       
        if(res.data.code == 200){
          body = res.data.newslist;
          var temp = JSON.stringify(body);
          console.log(temp);
         
          that.setData({
            title:res.data.newslist[0].title,
            author:res.data.newslist[0].author,
            content: res.data.newslist[0].content,

            title1:res.data.newslist[1].title,
            author1:res.data.newslist[1].author,
            content1: res.data.newslist[1].content,

            title2:res.data.newslist[2].title,
            author2:res.data.newslist[2].author,
            content2: res.data.newslist[2].content,

            title3:res.data.newslist[3].title,
            author3:res.data.newslist[3].author,
            content3: res.data.newslist[3].content,

            title4:res.data.newslist[4].title,
            author4:res.data.newslist[4].author,
            content4: res.data.newslist[4].content,

            title5:res.data.newslist[5].title,
            author5:res.data.newslist[5].author,
            content5: res.data.newslist[5].content,

            title6:res.data.newslist[6].title,
            author6:res.data.newslist[6].author,
            content6: res.data.newslist[6].content,

            title7:res.data.newslist[7].title,
            author7:res.data.newslist[7].author,
            content7: res.data.newslist[7].content,

            title8:res.data.newslist[8].title,
            author8:res.data.newslist[8].author,
            content8: res.data.newslist[8].content,

            title9:res.data.newslist[9].title,
            author9:res.data.newslist[9].author,
            content9: res.data.newslist[9].content,

          
          })
        
      }else{
          that.setData({
            content: res.data.msg
          }) 
      }
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})